package com.hzit.mmcb.core.controller.api;


import com.hzit.common.result.R;
import com.hzit.mmb.base.utils.JwtUtils;
import com.hzit.mmcb.core.pojo.vo.BorrowerVO;
import com.hzit.mmcb.core.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ljh
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {
    @Autowired
    private BorrowerService borrowerService;

    @PostMapping("/save")
    public R save(@RequestBody BorrowerVO vo, @RequestHeader("token") String token){
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerVOByUserId(vo,userId);
        return R.ok().message("信息上传成功");
    }

    @GetMapping("auth/getBorrowerStatus")
    public R getBorrowerStatus(@RequestHeader("token")String token){
        Long userId = JwtUtils.getUserId(token);
        Integer status=borrowerService.getStatus(userId);
        return R.ok().data("borrowerStatus",status);
    }

    /**
     * 获取贷款金额上限
     */
    @GetMapping("/getBorrowAmount")
    @ApiOperation("获取贷款金额上限")
    public R getBorrowAmount(@RequestHeader("token") String token){
        Long userId = JwtUtils.getUserId(token);
        BigDecimal borrowAmount= borrowerService.getBorrowAmount(userId);
        return R.ok().data("borrowAmount",borrowAmount);
    }
}

